package com.mc.sort;

import java.util.Arrays;

/**
 * @Description: 冒泡排序
 * @Author: MoChen
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] arrs = {1, 2, 5, 3, 6, 7, 4};
        BubbleSort bs = new BubbleSort();
        System.out.println(Arrays.toString(bs.bubbleSort(arrs)));
    }

    /**
     * 冒泡排序
     */
    public int[] bubbleSort(int[] arrs){
        for(int i = 0; i < arrs.length; i++){
            for(int j = 0; j < arrs.length - i - 1; j++){
                if(arrs[j] > arrs[j + 1]){
                    int temp = arrs[j];
                    arrs[j] = arrs[j + 1];
                    arrs[j + 1] = temp;
                }
            }
        }
        return arrs;
    }
}
